package com.itheima.day09泛型和二叉树.练习;

import java.sql.Statement;
import java.util.Collections;
import java.util.Comparator;
import java.util.TreeSet;

/*请创建Student类表示每一名学生，尝试使用集合的相关知识对这5名学生按照总分降序排序，如果总分一样，则按
照语文成绩降序。排序完成之后遍历集合，并打印结果，打印效果如下：*/
public class Demo3 {
    public static void main(String[] args) {
        TreeSet<Student> set=new TreeSet<Student>((Student o1,Student o2)->
        {return o2.sum()-o1.sum()==0?o2.getChinese()-o1.getChinese():o2.sum()-o1.sum();});
        Collections.addAll(set,new Student("马冬梅", 92, 87, 93)
        ,new Student("夏洛", 79 ,97 ,81)
        ,new Student("袁华", 97, 93, 94)
        ,new Student("大春", 85, 88, 91)
        ,new Student("秋雅", 95, 90, 99));

        for (Student student : set) {
            System.out.println(student);
        }
    }
}
class Student{
    private String name;
    private int chinese;
    private int math;
    private int english;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getChinese() {
        return chinese;
    }

    public void setChinese(int chinese) {
        this.chinese = chinese;
    }

    public int getMath() {
        return math;
    }

    public void setMath(int math) {
        this.math = math;
    }

    public int getEnglish() {
        return english;
    }

    public void setEnglish(int english) {
        this.english = english;
    }

    public Student(String name, int chinese, int math, int english) {
        this.name = name;
        this.chinese = chinese;
        this.math = math;
        this.english = english;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", chinese=" + chinese +
                ", math=" + math +
                ", english=" + english +
                '}';
    }

    public Student() {
    }
    public int  sum(){
        return this.chinese+this.math+this.english;
    }
}